"""
SCP文件传输工具模块。
"""

import enum
import subprocess
from typing import Dict, Tuple

class ServerType(enum.Enum):
    """服务器类型枚举。"""
    DEV = 'dev'
    TEST = 'test'
    PROD = 'prod'

def get_server_info(server_type: ServerType) -> Tuple[str, int]:
    """
    获取服务器信息。
    
    Args:
        server_type: 服务器类型
        
    Returns:
        服务器IP和端口元组
    """
    server_info: Dict[ServerType, Tuple[str, int]] = {
        ServerType.DEV: ('192.168.1.100', 22),
        ServerType.TEST: ('192.168.1.101', 22),
        ServerType.PROD: ('192.168.1.102', 22)
    }
    return server_info[server_type]

def scp_upload(local_path: str, remote_path: str, server_type: ServerType) -> bool:
    """
    使用SCP上传文件到服务器。
    
    Args:
        local_path: 本地文件路径
        remote_path: 远程文件路径
        server_type: 服务器类型
        
    Returns:
        上传是否成功
    """
    ip, port = get_server_info(server_type)
    cmd = f'scp -P {port} {local_path} root@{ip}:{remote_path}'
    
    try:
        subprocess.run(cmd, shell=True, check=True)
        return True
    except subprocess.CalledProcessError:
        return False 